﻿using Microsoft.Win32;
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Runtime.Serialization.Formatters.Binary;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Xml;
using System.Configuration;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;

namespace VisualWix
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private const string DEFAULT_REPOSITORY_PATH = @"C:\Temp";
        private const string CUSTOM_FOLDER_PREFIX = "Custom_Folder_";

        public ObservableCollection<Item> myCollection = new ObservableCollection<Item>();
        DirectoryItem myTargetFolder = new DirectoryItem();
        DirectoryItem myShortcutsFolder = new DirectoryItem();
        List<WixProductProperty> myProperties = new List<WixProductProperty>();
        Wix myWixDetails = null;
        string myFileName;

        public MainWindow()
            : this(string.Empty)
        {

        }

        public MainWindow(string fileToLoad)
        {
            myFileName = fileToLoad;

            InitializeComponent();

            try
            {
                LoadWixContents();
            }
            catch
            {
                System.Windows.MessageBox.Show(string.Format("Unable to load the file '{0}'. Creating a new wix project!", myFileName));
                myFileName = string.Empty;
                LoadWixContents();
            }

            ButtonAddFile.Content = ">>";
            ButtonRemoveFile.Content = "<<";

            //CreateDefaultShortcutFolders();

            ItemToContextMenuConverter.RootFolderContextMenu = GetContextMenuForSystemFolder();
            ItemToContextMenuConverter.FolderContextMenu = GetContextMenuForFolder();
            ItemToContextMenuConverter.FileContextMenu = GetContextMenuForFile();
            ItemToContextMenuConverter.ShortcutRootFolderContextMenu = GetContextMenuForShortcutRootFolder();
            ItemToContextMenuConverter.ShortcutFolderContextMenu = GetContextMenuForShortcutFolder();

            TreeViewFileInformation.ItemsSource = myCollection;

            string repositoryPath = ConfigurationManager.AppSettings["RepositoryLocation"];
            if (string.IsNullOrWhiteSpace(repositoryPath) || !System.IO.Directory.Exists(repositoryPath))
            {
                repositoryPath = DEFAULT_REPOSITORY_PATH;
            }
            TreeViewFolderExplorer.ItemsSource = GetItems(null, repositoryPath);
        }

        private void LoadWixContents()
        {
            myWixDetails = Wix.LoadFromFile(myFileName);
            if (myWixDetails == null)
            {
                myWixDetails = new Wix();
                myWixDetails.Initialize();
            }
            else
            {
                myWixDetails.GetDirectoryStructure(myTargetFolder, myShortcutsFolder);
            }

            PopulateProductDetails();

            if (myWixDetails.Product.Property != null)
            {
                myProperties = new List<WixProductProperty>(myWixDetails.Product.Property);
            }
            myCollection.Clear();

            myTargetFolder.Name = "TARGETFOLDER";
            myTargetFolder.IsContextMenuEnabled = true;
            myTargetFolder.ParentItem = null;
            myTargetFolder.HierarchyType = HierarchyType.RootFolder;
            myTargetFolder.IsDragDropEnabled = true;
            myCollection.Add(myTargetFolder);


            myShortcutsFolder.Name = "SHORTCUTS";
            myShortcutsFolder.IsContextMenuEnabled = true;
            myShortcutsFolder.ParentItem = null;
            myShortcutsFolder.HierarchyType = HierarchyType.ShortcutRootFolder;
            myShortcutsFolder.IsDragDropEnabled = false;
            myCollection.Add(myShortcutsFolder);

        }

        #region Context Menus
        private ContextMenu GetContextMenuForSystemFolder()
        {
            ContextMenu menu = new ContextMenu();
            MenuItem menuItemAddSystemFolder = new MenuItem();
            menuItemAddSystemFolder.Name = "AddSystemFolder";
            menuItemAddSystemFolder.Header = "Add System Folder";

            var values = Enum.GetValues(typeof(SystemDirectoryType));
            foreach (var item in values)
            {
                MenuItem subMenuItem = new MenuItem();
                subMenuItem.Header = item.ToString();
                subMenuItem.Name = item.ToString();
                subMenuItem.Click += menuItemAddSystemFolder_Click;
                menuItemAddSystemFolder.Items.Add(subMenuItem);
            }

            menu.Items.Add(menuItemAddSystemFolder);

            return menu;
        }

        private ContextMenu GetContextMenuForShortcutRootFolder()
        {
            ContextMenu menu = new ContextMenu();
            MenuItem menuItemAddSystemShortcutFolder = new MenuItem();
            menuItemAddSystemShortcutFolder.Name = "AddSystemFolder";
            menuItemAddSystemShortcutFolder.Header = "Add System Folder";

            MenuItem subMenuItem = new MenuItem();
            subMenuItem.Header = "DesktopFolder";
            subMenuItem.Name = "DesktopFolder";
            subMenuItem.Click += menuItemAddSystemShortcutFolder_Click;
            menuItemAddSystemShortcutFolder.Items.Add(subMenuItem);

            subMenuItem = new MenuItem();
            subMenuItem.Header = "ProgramMenuFolder";
            subMenuItem.Name = "ProgramMenuFolder";
            subMenuItem.Click += menuItemAddSystemShortcutFolder_Click;
            menuItemAddSystemShortcutFolder.Items.Add(subMenuItem);

            menu.Items.Add(menuItemAddSystemShortcutFolder);

            return menu;
        }

        private void menuItemAddSystemShortcutFolder_Click(object sender, RoutedEventArgs e)
        {
            MenuItem item = sender as MenuItem;
            SystemDirectoryType directoryType = (SystemDirectoryType)Enum.Parse(typeof(SystemDirectoryType), item.Name);

            DirectoryItem systemDirectory = new DirectoryItem();
            systemDirectory.Name = item.Name;
            systemDirectory.ParentItem = myShortcutsFolder;
            systemDirectory.IsContextMenuEnabled = true;
            systemDirectory.HierarchyType = HierarchyType.SystemShortcutFolder;

            myShortcutsFolder.Items.Add(systemDirectory);
        }


        private ContextMenu GetContextMenuForFolder()
        {
            ContextMenu menu = new ContextMenu();
            MenuItem menuItemAddFolder = new MenuItem();
            menuItemAddFolder.Name = "AddFolder";
            menuItemAddFolder.Header = "Add Folder";
            menuItemAddFolder.Click += menuItemAddFolder_Click;

            MenuItem menuItemAddFile = new MenuItem();
            menuItemAddFile.Name = "AddFile";
            menuItemAddFile.Header = "Add File(s)";
            menuItemAddFile.Click += menuItemAddFile_Click;

            MenuItem menuItemDelete = new MenuItem();
            menuItemDelete.Name = "Delete";
            menuItemDelete.Header = "Delete";
            menuItemDelete.Click += menuItemDelete_Click;

            menu.Items.Add(menuItemAddFolder);
            menu.Items.Add(menuItemAddFile);
            menu.Items.Add(menuItemDelete);

            return menu;
        }

        private ContextMenu GetContextMenuForFile()
        {
            ContextMenu menu = new ContextMenu();

            MenuItem menuItemDelete = new MenuItem();
            menuItemDelete.Name = "Delete";
            menuItemDelete.Header = "Delete";
            menuItemDelete.Click += menuItemDelete_Click;

            MenuItem menuItemRename = new MenuItem();
            menuItemRename.Name = "Rename";
            menuItemRename.Header = "Rename";
            menuItemRename.Click += menuItemRename_Click;

            menu.Items.Add(menuItemRename);
            menu.Items.Add(menuItemDelete);

            return menu;
        }

        private ContextMenu GetContextMenuForShortcutFolder()
        {
            ContextMenu menu = new ContextMenu();
            MenuItem menuItemAddFolder = new MenuItem();
            menuItemAddFolder.Name = "AddFolder";
            menuItemAddFolder.Header = "Add Folder";
            menuItemAddFolder.Click += menuItemAddFolder_Click;

            MenuItem menuItemCreateShortcut = new MenuItem();
            menuItemCreateShortcut.Name = "CreateShortcut";
            menuItemCreateShortcut.Header = "Create Shortcut";
            menuItemCreateShortcut.Click += menuItemCreateShortcut_Click;

            MenuItem menuItemDelete = new MenuItem();
            menuItemDelete.Name = "Delete";
            menuItemDelete.Header = "Delete";
            menuItemDelete.Click += menuItemDelete_Click;

            menu.Items.Add(menuItemAddFolder);
            menu.Items.Add(menuItemCreateShortcut);
            menu.Items.Add(menuItemDelete);

            return menu;
        }

        private void menuItemCreateShortcut_Click(object sender, RoutedEventArgs e)
        {
            DirectoryItem selectedItem = (DirectoryItem)TreeViewFileInformation.SelectedItem;

            ShortcutWindow createShortcutWindow = new ShortcutWindow();
            createShortcutWindow.TargetDirectoryInfo = myTargetFolder;//.DeepClone();// TODO: DeepClone Not Required...?
            createShortcutWindow.ShowDialog();

            if (createShortcutWindow.ShortcutInfo != null)
            {
                ShortcutItem shortcut = createShortcutWindow.ShortcutInfo;
                shortcut.ParentItem = selectedItem;
                shortcut.IsContextMenuEnabled = true;
                shortcut.HierarchyType = HierarchyType.Shortcut;

                selectedItem.Items.Add(shortcut);
            }
        }
        #endregion

        #region Add/Remove Items thru Mouse Click
        void menuItemAddFile_Click(object sender, RoutedEventArgs e)
        {
            // TODO: Add actual File(s)
            OpenFileDialog openFileDialog = new OpenFileDialog();

            // Set filter options and filter index.
            openFileDialog.Filter = "Executable Files |*.dll;*.exe;*.xml | All Files (*.*)|*.*";
            openFileDialog.FilterIndex = 1;
            openFileDialog.Title = "Select Files";
            openFileDialog.Multiselect = true;

            // Call the ShowDialog method to show the dialog box.
            bool? userClickedOK = openFileDialog.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOK == true)
            {
                DirectoryItem selectedItem = (DirectoryItem)TreeViewFileInformation.SelectedItem;
                foreach (var item in openFileDialog.FileNames)
                {
                    FileItem file = new FileItem();
                    file.Name = Path.GetFileName(item);
                    file.Source = item;
                    file.ParentItem = selectedItem;
                    file.IsContextMenuEnabled = true;
                    file.HierarchyType = HierarchyType.File;

                    selectedItem.Items.Add(file);
                }
            }
        }

        void menuItemAddFolder_Click(object sender, RoutedEventArgs e)
        {
            // TODO: Add actual Folder
            Folder folderForm = new Folder();

            bool? clickedOk = folderForm.ShowDialog();
            string folderName = folderForm.FolderName;
            folderForm = null;

            if (clickedOk == true)
            {
                DirectoryItem selectedItem = TreeViewFileInformation.SelectedItem as DirectoryItem;

                DirectoryItem item = new DirectoryItem();
                item.Name = folderName;
                item.ParentItem = selectedItem;
                item.IsContextMenuEnabled = true;
                item.IsDragDropEnabled = selectedItem.IsDragDropEnabled;
                item.HierarchyType = (selectedItem.HierarchyType == HierarchyType.SystemFolder || selectedItem.HierarchyType == HierarchyType.Folder) ?
                                        HierarchyType.Folder : HierarchyType.ShortcutFolder;

                selectedItem.Items.Add(item);
            }
        }

        void menuItemAddSystemFolder_Click(object sender, RoutedEventArgs e)
        {
            MenuItem item = sender as MenuItem;
            SystemDirectoryType directoryType = (SystemDirectoryType)Enum.Parse(typeof(SystemDirectoryType), item.Name);

            DirectoryItem systemDirectory = new DirectoryItem();

            if (directoryType == SystemDirectoryType.CustomFolder)
            {
                Folder folderForm = new Folder();
                bool? clickedOk = folderForm.ShowDialog();
                string folderName = folderForm.FolderName;
                folderForm = null;

                if (clickedOk == true)
                {
                    string customFolderId = folderName.Replace("\\", "_");
                    string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()) + " " + "\t";
                    Regex regex = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
                    customFolderId = CUSTOM_FOLDER_PREFIX + regex.Replace(customFolderId, string.Empty);
                    systemDirectory.Name = customFolderId;

                    WixProductProperty property = new WixProductProperty();
                    property.Id = customFolderId;
                    property.Value = folderName;

                    myProperties.Add(property);
                }
                else
                {
                    return;
                }
            }
            else
            {
                systemDirectory.Name = directoryType.ToString();
            }
            systemDirectory.ParentItem = myTargetFolder;
            systemDirectory.IsContextMenuEnabled = true;
            systemDirectory.IsDragDropEnabled = myTargetFolder.IsDragDropEnabled;
            systemDirectory.HierarchyType = HierarchyType.SystemFolder;

            myTargetFolder.Items.Add(systemDirectory);
        }

        void menuItemDelete_Click(object sender, RoutedEventArgs e)
        {
            Item selectedItem = TreeViewFileInformation.SelectedItem as Item;
            RemoveItem(selectedItem);
        }

        void menuItemRename_Click(object sender, RoutedEventArgs e)
        {
            Item selectedItem = TreeViewFileInformation.SelectedItem as Item;
            RenameItem(selectedItem);
        }

        private void RenameItem(Item selectedItem)
        {
            //TODO
        }
        #endregion

        #region Tweak for getting SelectedItem
        private void TreeViewItem_PreviewMouseRightButtonDown(object sender, MouseEventArgs e)
        {
            TreeViewItem treeViewItem = VisualUpwardSearch(e.OriginalSource as DependencyObject);

            if (treeViewItem != null)
            {
                treeViewItem.Focus();
                e.Handled = true;
            }
        }

        static TreeViewItem VisualUpwardSearch(DependencyObject source)
        {
            while (source != null && !(source is TreeViewItem))
                source = VisualTreeHelper.GetParent(source);

            return source as TreeViewItem;
        }
        #endregion

        #region Get Folders/Files Tree
        public static ObservableCollection<Item> GetAllItems()
        {
            var items = new ObservableCollection<Item>();
            foreach (var item in System.IO.Directory.GetLogicalDrives())
            {
                DirectoryItem logicalDrive = new DirectoryItem();
                logicalDrive.Name = item;
                logicalDrive.IsContextMenuEnabled = false;
                logicalDrive.HierarchyType = HierarchyType.RootFolder;
                logicalDrive.Items = GetItems(logicalDrive, item);
                items.Add(logicalDrive);
            }
            return items;
        }

        public static ObservableCollection<Item> GetItems(DirectoryItem parent, string path)
        {
            var items = new ObservableCollection<Item>();

            try
            {
                var dirInfo = new DirectoryInfo(path);

                foreach (var directory in dirInfo.GetDirectories())
                {
                    var item = new DirectoryItem
                    {
                        Name = directory.Name,
                        ParentItem = parent,
                        IsContextMenuEnabled = false,
                        HierarchyType = HierarchyType.Folder
                    };

                    item.Items = GetItems(item, directory.FullName);
                    items.Add(item);
                }

                foreach (var file in dirInfo.GetFiles())
                {
                    var item = new FileItem
                    {
                        Name = file.Name,
                        ParentItem = parent,
                        IsContextMenuEnabled = false,
                        HierarchyType = HierarchyType.File,
                        //TargetName = file.Name,
                        Source = file.FullName
                    };

                    items.Add(item);
                }
            }
            catch
            {

            }

            return items;
        }
        #endregion

        #region Add/Remove Files in TreeView

        private void ButtonAddFile_Click_1(object sender, RoutedEventArgs e)
        {
            Item selectedItem = TreeViewFolderExplorer.SelectedItem as Item;
            if (selectedItem == null)
            {
                MessageBox.Show("Please select a Folder/File to add...!", "SOURCE");
            }
            else
            {
                DirectoryItem directory = TreeViewFileInformation.SelectedItem as DirectoryItem;
                if (directory == null)
                {
                    MessageBox.Show("Please select a Target Directory...!", "TARGET");
                }
                else
                {
                    if (string.Compare(directory.Name, "TARGETFOLDER", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        MessageBox.Show("Folder/File cannot be added directly to Target-Folder, Please select a sub-directory...!", "TARGET");
                    }
                    else
                    {
                        if (directory.IsDragDropEnabled)// TODO: Since Clonning added here, check for id, objects are already different.
                        {
                            Item clonedItem = selectedItem.DeepClone();

                            EnableContextMenu(clonedItem);
                            clonedItem.ParentItem = directory;
                            directory.Items.Add(clonedItem);
                        }
                        else
                        {
                            MessageBox.Show("Folder/File cannot be added to Shortcuts Folder, Please select another directory...!", "TARGET");
                        }
                    }
                }
            }
        }

        private void EnableContextMenu(Item clonedItem)
        {
            if (clonedItem == null)
            {
                throw new ArgumentNullException("clonedItem", "Item cannot be null");
            }
            clonedItem.IsContextMenuEnabled = true;
            DirectoryItem directory = clonedItem as DirectoryItem;
            if (directory != null && directory.Items != null && directory.Items.Count > 0)
            {
                foreach (var item in directory.Items)
                {
                    EnableContextMenu(item);
                }
            }
        }

        private void ButtonRemoveFile_Click_1(object sender, RoutedEventArgs e)
        {
            Item selectedItem = TreeViewFileInformation.SelectedItem as Item;
            RemoveItem(selectedItem);
        }

        private void RemoveItem(Item selectedItem)
        {
            if (selectedItem == null)
            {
                MessageBox.Show("Please select a Folder/File to remove...!", "TARGET");
            }
            else
            {
                DirectoryItem parent = selectedItem.ParentItem as DirectoryItem;
                if (parent != null)
                {
                    if (selectedItem.ID.StartsWith(CUSTOM_FOLDER_PREFIX))
                    {
                        WixProductProperty productProperty = myProperties.FirstOrDefault(property => string.Compare(property.Id, selectedItem.ID, StringComparison.OrdinalIgnoreCase) == 0);
                        if (productProperty != null)
                        {
                            myProperties.Remove(productProperty);
                        }
                    }

                    parent.Items.Remove(selectedItem);
                }
            }
        }
        #endregion

        #region Generate wxs
        private void ButtonSave_Click_1(object sender, RoutedEventArgs e)
        {
            Uri wxsPathUri = myWixDetails.GetWxsFilepath();
            string wxsFile = wxsPathUri != null ? wxsPathUri.OriginalString : string.Empty;
            if (string.IsNullOrWhiteSpace(wxsFile))
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Title = "Browse Wix Files";
                saveFileDialog.DefaultExt = "wxs";
                saveFileDialog.Filter = "wxs files (*.wxs)|*.wxs|All files (*.*)|*.*";
                saveFileDialog.AddExtension = true;

                bool? userClickedOK = saveFileDialog.ShowDialog();

                // Process input if the user clicked OK.
                if (userClickedOK == true)
                {
                    wxsFile = saveFileDialog.FileName;
                    myWixDetails.SetWxsFilePath(wxsFile);
                }
                else
                {
                    return;
                }
            }

            myWixDetails.UpdateProductDetails(TextBoxProductName.Text, TextBoxProductVersion.Text, TextBoxProductManufacturer.Text);
            myWixDetails.UpdatePackageDetails(TextBoxPackageDescription.Text, ComboBoxPackageInstallScope.Text,
                ComboBoxPackagePlatform.Text, ComboBoxPackageInstallPrivileges.Text);
            myWixDetails.UpdateDirectoryStructure(myTargetFolder, myShortcutsFolder);
            myWixDetails.UpdateProperties(myProperties);
            myWixDetails.SaveToFile();

            MessageBox.Show("File saved successfully.");
        }

        private void ButtonCancel_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        #endregion

        #region Show Properties
        private void ButtonPropertiesUpdate_Click_1(object sender, RoutedEventArgs e)
        {
            Item selectedItem = TreeViewFileInformation.SelectedItem as Item;
            if (selectedItem != null)
            {
                if (selectedItem.HierarchyType == HierarchyType.File)
                {
                    FileItem file = (FileItem)selectedItem;
                    file.Name = TextBoxPropertiesName.Text;
                    file.KeyPath = ComboBoxPropertiesKeyPath.SelectedIndex == 0 ? true : false;
                }
                else if (selectedItem.HierarchyType == HierarchyType.Shortcut)
                {
                    ShortcutItem shortcut = (ShortcutItem)selectedItem;
                    shortcut.Name = TextBoxPropertiesName.Text;
                    shortcut.Description = TextBoxPropertiesDescription.Text;
                }
            }
        }

        private void TreeViewFileInformation_SelectedItemChanged_1(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            Item selectedItem = TreeViewFileInformation.SelectedItem as Item;
            if (selectedItem != null)
            {
                if (selectedItem.HierarchyType == HierarchyType.File)
                {
                    SetPropertiesVisibility(true);

                    FileItem file = (FileItem)selectedItem;
                    TextBoxPropertiesName.Text = file.Name;
                    TextBoxPropertiesSource.Text = Path.GetFullPath(file.Source);
                    ComboBoxPropertiesKeyPath.Text = file.KeyPath ? "yes" : "no";
                }
                else if (selectedItem.HierarchyType == HierarchyType.Shortcut)
                {
                    SetPropertiesVisibility(false);

                    ShortcutItem shortcut = (ShortcutItem)selectedItem;
                    TextBoxPropertiesName.Text = shortcut.Name;
                    // Make absolute path
                    TextBoxPropertiesSource.Text = CreateAbsolutePath(shortcut);
                    TextBoxPropertiesDescription.Text = shortcut.Description;
                }
                else
                {
                    DirectoryItem customDirectory = selectedItem as DirectoryItem;
                    if (customDirectory != null && customDirectory.ID.StartsWith(CUSTOM_FOLDER_PREFIX))
                    {
                        foreach (var item in myProperties)
                        {
                            if (item.Id == customDirectory.ID)
                            {
                                SetPropertiesVisibility(false);
                                TextBoxPropertiesName.Text = item.Id;
                                TextBoxPropertiesSource.Text = item.Value;
                                TextBoxPropertiesDescription.Visibility = System.Windows.Visibility.Collapsed;
                                TextBlockPropertiesDescription.Visibility = System.Windows.Visibility.Collapsed;
                                ButtonPropertiesUpdate.Visibility = System.Windows.Visibility.Collapsed;
                            }
                        }
                    }
                    else
                    {
                        GridProperties.Visibility = System.Windows.Visibility.Hidden;
                    }
                }
            }
        }

        private string CreateAbsolutePath(ShortcutItem shortcut)
        {
            DirectoryItem directory = Find(myTargetFolder, shortcut.TargetDirectory);
            if (directory != null)
            {
                foreach (FileItem item in directory.Items)
                {
                    string filename = Path.GetFileName(item.Source);
                    if (string.Compare(filename, shortcut.TargetFile, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        return Path.GetFullPath(item.Source);
                    }
                }
            }

            return shortcut.TargetFile;
        }

        public static DirectoryItem Find(DirectoryItem node, string id)
        {
            if (node == null)
            {
                return null;
            }
            if (node.ID == id)
            {
                return node;
            }
            foreach (var child in node.Items)
            {
                DirectoryItem directory = child as DirectoryItem;
                if (directory != null)
                {
                    var found = Find(directory, id);
                    if (found != null)
                    {
                        return found;
                    }
                }
            }

            return null;
        }

        private void SetPropertiesVisibility(bool filePropertiesVisible)
        {
            Visibility fileVisibility = filePropertiesVisible ? Visibility.Visible : Visibility.Collapsed;
            Visibility shortcutVisibility = filePropertiesVisible ? Visibility.Collapsed : Visibility.Visible;

            GridProperties.Visibility = System.Windows.Visibility.Visible;
            ButtonPropertiesUpdate.Visibility = System.Windows.Visibility.Visible;

            TextBlockPropertiesKeyPath.Visibility = fileVisibility;
            ComboBoxPropertiesKeyPath.Visibility = fileVisibility;

            TextBlockPropertiesDescription.Visibility = shortcutVisibility;
            TextBoxPropertiesDescription.Visibility = shortcutVisibility;
        }
        #endregion

        #region Load UI from Wix
        private void PopulateProductDetails()
        {
            WixProduct product = myWixDetails.Product;

            TextBoxProductName.Text = product.Name;
            TextBoxProductVersion.Text = product.Version;
            TextBoxProductManufacturer.Text = product.Manufacturer;

            WixProductPackage package = myWixDetails.Product.Package;
            TextBoxPackageDescription.Text = package.Description;
            ComboBoxPackageInstallScope.Text = package.InstallScope;
            ComboBoxPackagePlatform.Text = package.Platform;
            ComboBoxPackageInstallPrivileges.Text = package.InstallPrivileges;
        }

        #endregion
    }

}
